//
// Created by hoyin on 2022/2/15.
//

#ifndef AUST_RM_VISION_2022_MATCHER_H
#define AUST_RM_VISION_2022_MATCHER_H

#include "Macros.h"
#include "opencv2/opencv.hpp"

using namespace cv;
using namespace std;

class Matcher {
private:
	Mat originImage, targetImage;
	cuda::GpuMat gOriginImage, gTargetImage;
	vector<Point> contoursMatch();
	vector<Point> contoursMatchWithCUDA();

	static void clearRect(Rect2d &rect2D);
	static void clearRect(RotatedRect &rotatedRect);

	bool isGpuAccelerate = false;
public:
	explicit Matcher(Mat &target, const Size &srcSize = Size(0, 0), const Size &targetSize = Size(0, 0));
	explicit Matcher(cuda::GpuMat &target, const Size &srcSize = Size(0, 0), const Size &targetSize = Size(0, 0));
	Matcher();

	void setGpuAccelMode(bool gpuAccel) {
		isGpuAccelerate = gpuAccel;
	}

	bool getGpuAccelMode() {
		return isGpuAccelerate;
	}

	void setOriginImage(Mat& src, const Size& size = Size(0, 0));
	void setTargetImage(Mat& target, const Size& size = Size(0, 0));

	void setOriginImage(cuda::GpuMat& src, const Size& size = Size(0, 0));
	void setTargetImage(cuda::GpuMat& target, const Size& size = Size(0, 0));

	Rect2d templateMatch(double threshold, int method);
	Rect2d templateMatchWithCUDA(double threshold, int method);
	void contoursMatch(RotatedRect &result);
	void contoursMatch(Rect2d &result);

};


#endif //AUST_RM_VISION_2022_MATCHER_H
